<template>
  <div class="securityCenter">
    <zyInfoPanel title="安全中心" :showUnfoldButton="false" class="orderInfoItem">
      <div class="securityCenterContent">
        <zy-modal-info :model-info="securityInfo"></zy-modal-info>
        <div class="btnArea">
          <div class="leftTitle"></div>
          <div class="rightContent">
            <zy-button @click="savePassword" type="primary" class="btn">保存</zy-button>
          </div>
        </div>
      </div>
    </zyInfoPanel>
  </div>
</template>

<script>
	export default {
		name: "CSecurityCenter",
		props: {},
		data() {
			return {
				securityInfo: [
					{
						title: '原密码',
						name: 'oldPassword',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
					{
						title: '新密码',
						name: 'password',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
					{
						title: '重复新密码',
						name: 'confirmPassword',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
				]
			};
		},
		computed: {},
		watch: {},
		components: {},
		methods: {
			savePassword() {
				let postData = {};
				this.securityInfo.forEach(item => {
					postData[item.name] = item.value;
				});
				if (!postData.oldPassword) {
					return this.$message.error("请输入原密码")
				}
				if (!postData.password) {
					return this.$message.error("请输入新密码")
				}
				if (!postData.confirmPassword) {
					return this.$message.error("请输入确认密码")
				}
				if (postData.confirmPassword != postData.password) {
					return this.$message.error("确认密码与新密码不一致")
				}
				this.$axios.post(this.$api.c_editPassword, {
					new_pas: postData.password,
					old_pas: postData.oldPassword,
					new_repeat_pas: postData.confirmPassword,
				}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.$message.success(msg);
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			}
		},
		mounted() {
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/cooperate/securityCenter/securityCenter/index.less">

</style>
